package com.sqly.doc.menu.fjh;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Environment;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ihidea.multilinechooselib.MultiLineChooseLayout;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.sqly.doc.R;
import com.sqly.doc.base.MyBaseActivity;
import com.sqly.doc.menu.camera.CameraChoose;
import com.sqly.doc.pojo.FjhDycrhsf;
import com.sqly.doc.pojo.JuMin;
import com.sqly.doc.pojo.RetMsg;
import com.sqly.doc.user.choose_user;
import com.sqly.doc.util.BinderPojo;
import com.sqly.doc.util.BinderUtil;
import com.sqly.doc.util.CreateBitmap;
import com.sqly.doc.util.DateConvert;
import com.sqly.doc.util.HttpUrl;
import com.sqly.doc.util.MyToastUtil;
import com.sqly.doc.util.NetWorkUtils;
import com.sqly.doc.util.PictureUtil;
import com.sqly.doc.util.SharedPreferencesUtils;
import com.sqly.doc.util.SweetAlertDialogUtil;
import com.sqly.doc.util.Url;
import com.sqly.doc.util.UserClient;
import com.sqly.doc.util.WriteActivity;
import com.sqly.doc.view.CustomDatePicker;
import com.sqly.doc.view.StringUtils;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Locale;

import cz.msebera.android.httpclient.Header;

//import cn.pedant.SweetAlert.SweetAlertDialog;

/**
 * Created by Administrator on 2017/11/22 0022.
 */

public class fjhdycrhsf extends MyBaseActivity {

    FjhDycrhsf obj;
    JuMin j;
    private CustomDatePicker customDatePicker;
    Context con = fjhdycrhsf.this;
    /////////////////////////////////////////////////////
    RadioGroup sffs, hzlx, tjqk, nyqk;
    MultiLineChooseLayout zzjtz, yplx;
    private List<String> zzjtzdata = new ArrayList<>();
    private List<String> yplxdata = new ArrayList<>();

    //化疗方案
    //EditText hlfa;
    //生活方式评估
    //EditText xiyan, yinjiu;
    //健康教育及培训
    //EditText qydd, qysj;

    RadioGroup yf, ddryxz;
    //家庭居住环境评估
    RadioGroup dddjs, tfqk;
    RadioGroup r1, r2, r3, r4, r5, r6, r7, r8, r9;
    LinearLayout back;

    //只需要在每个ID上设置对应的注解即可
    @BinderPojo(value = R.id.SFJLH, name = "SFJLH", pojoProperty = true)
    private TextView SFJLH;

    @BinderPojo(value = R.id.XINGMING, name = "XINGMING", pojoProperty = true, require = true, promptMsg = "请选择患者信息")
    private TextView XINGMING;

    @BinderPojo(value = R.id.SFRQ, name = "SFRQ", pojoProperty = true, require = true, promptMsg = "请选择随访日期")
    private TextView SFRQ;

    @BinderPojo(value = R.id.ZZQT, name = "ZZQT", pojoProperty = true)
    private EditText ZZQT;//症状其他

    @BinderPojo(value = R.id.YYHLFA, name = "YYHLFA", pojoProperty = true)
    private EditText YYHLFA;//化疗方案

    @BinderPojo(value = R.id.SHXY, name = "SHXY", pojoProperty = true)
    private EditText SHXY;//生活-吸烟量

    @BinderPojo(value = R.id.SHXYZD, name = "SHXYZD", pojoProperty = true)
    private EditText SHXYZD;//生活-吸烟-指导量

    @BinderPojo(value = R.id.SHYJ, name = "SHYJ", pojoProperty = true)
    private EditText SHYJ;//生活-饮酒-指导量

    @BinderPojo(value = R.id.SHYJZD, name = "SHYJZD", pojoProperty = true)
    private EditText SHYJZD;//生活-饮酒-指导量

    @BinderPojo(value = R.id.QYDD, name = "QYDD", pojoProperty = true)
    private EditText QYDD;//取药地点

    @BinderPojo(value = R.id.QYSJ, name = "QYSJ", pojoProperty = true)
    private EditText QYSJ;//取药时间

    @BinderPojo(value = R.id.XCSFRQ, name = "XCSFRQ", pojoProperty = true, require = true, promptMsg = "请选择下次随访日期")
    private TextView XCSFRQ;

    //标题
    @BinderPojo(value = R.id.title)
    private TextView title;
    //标题
    @BinderPojo(value = R.id.uname)
    private TextView uname;

    ImageView sfysqm, brqm, xcqm;
    String sfysqmpic = "", brqmpic = "",xcqmpic ="";
    boolean isadd = false;//是否是新添加
    String url = "", JKDAH = "";

    ImageView xcpaizhao;
    TextView pz_record_id,jmqm_record_id, ysqm_record_id;
    boolean pzChange = false;

    @Override
    protected void initUI() {
        setContentView(R.layout.fjhdycrhsf);
        BinderUtil.exeFindById(fjhdycrhsf.this);
        if (NetWorkUtils.isNetworkConnected(con)) {
            if (getIntent().getStringExtra("type").equals("edit")) {
                obj = (FjhDycrhsf) getIntent().getExtras().getSerializable("b");
                init(obj);
                if (!StringUtils.isEmpty(obj.getImg())) {
                    //ImageLoader.getInstance().displayImage(Url.img_url() + obj.getImg(), brqm);
                    ImageLoader.getInstance().displayImage(Url.newStaticurl(SharedPreferencesUtils.getParam(con, "token", "").toString(), "2" ,obj.getImg()),brqm);
                }
                if (!StringUtils.isEmpty(obj.getImg1())) {
                    //ImageLoader.getInstance().displayImage(Url.img_url() + obj.getImg1(), sfysqm);
                    ImageLoader.getInstance().displayImage(Url.newStaticurl(SharedPreferencesUtils.getParam(con, "token", "").toString(), "2" ,obj.getImg1()),sfysqm);
                }

                if(!StringUtils.isEmpty(obj.getImg2())){
                    //ImageLoader.getInstance().displayImage(Url.img_url()+obj.getImg2(),xcqm);
                    ImageLoader.getInstance().displayImage(Url.newStaticurl(SharedPreferencesUtils.getParam(con, "token", "").toString(), "2" ,obj.getImg2()),xcqm);
                }
            }else {
                obj = new FjhDycrhsf();
                init(obj);
            }

        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (data != null) {
            if (requestCode == 1) {
                j = (JuMin) data.getExtras().getSerializable("j");
                getObject();
            }else if (requestCode == 8) {
                String record_id = (String) data.getExtras().getString("record_id");
                ysqm_record_id.setText(record_id);
                byte[] bis = data.getByteArrayExtra("bitmap");
                Bitmap bmp = BitmapFactory.decodeByteArray(bis, 0, bis.length);
                Bitmap bb = CreateBitmap.zoomImg(bmp, 1, 1);
                sfysqm.setImageBitmap(bb);
                sfysqmpic = CreateBitmap.saveMyBitmap(bb);
            }else if (requestCode == 9) {
                String record_id = (String) data.getExtras().getString("record_id");
                jmqm_record_id.setText(record_id);
                byte[] bis = data.getByteArrayExtra("bitmap");
                Bitmap bmp = BitmapFactory.decodeByteArray(bis, 0, bis.length);
                Bitmap bb = CreateBitmap.zoomImg(bmp, 1, 1);
                brqm.setImageBitmap(bb);
                brqmpic = CreateBitmap.saveMyBitmap(bb);
            }else if(requestCode == 119){
                String img_record_id = (String) data.getExtras().getString("img_record_id");
                pz_record_id.setText(img_record_id);
                pzChange = true;
                byte[] bis = data.getByteArrayExtra("bitmap");
                Bitmap bmp = BitmapFactory.decodeByteArray(bis, 0, bis.length);
                Bitmap bb = CreateBitmap.zoomImg(bmp, 1, 1);
                xcqm.setImageBitmap(bb);
            }
        }
    }

    public void getObject() {
        RequestParams ps = new RequestParams();
        ps.add("token", SharedPreferencesUtils.getParam(con, "token", "").toString());
        ps.add("type", "2");
        ps.add("CARDNUM", j.getCARDNUM());
        UserClient.get(HttpUrl.GetFjhDycrhsfGrjbxx, ps, new AsyncHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, Header[] headers, byte[] response) {
                String content = new String(response);
                RetMsg ret = JSON.parseObject(content, RetMsg.class);
                if (ret.getCode().equals("200")) {
                    JSONObject j = JSON.parseObject(ret.getRd());
                    obj = new FjhDycrhsf();
                    init(obj);
                    obj.setJKDAH(j.getString("JKDAH"));
                    obj.setXINGMING(j.getString("XINGMING"));
                    obj.setCARDNUM(j.getString("CARDNUM"));
                    JKDAH = j.getString("JKDAH");
                    XINGMING.setText(j.getString("XINGMING"));

                    isadd = true;
                } else {
                    SweetAlertDialogUtil.ErrorDialogNoFinish(con, "错误提示", ret.getInfo(), "确定");
                }
            }

            @Override
            public void onFinish() {
                super.onFinish();
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, byte[] errorResponse, Throwable e) {

                isadd = true;
                obj = new FjhDycrhsf();
                init(obj);
            }
        });
    }

    public void init(final FjhDycrhsf obj) {
        //运行时生成activity中所有控件的findViewById方法
        //BinderUtil.exeFindById(fjhdycrhsf.this);
        BinderUtil.initData(fjhdycrhsf.this, obj);
        //医师签名
        sfysqm = (ImageView) findViewById(R.id.sfysqm);
        sfysqm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivityForResult(new Intent(con, WriteActivity.class)
                        .putExtra("cardnum", obj.getCARDNUM())
                        .putExtra("tabId", null==obj.getSFJLH()||"".equals(obj.getSFJLH()) ? "noid" : obj.getSFJLH())
                        .putExtra("tabType", "fjhdycrhsf")
                        .putExtra("imageType", "img1")
                        .putExtra("class", "fjhdycrhsf.class"), 8);
            }
        });
        if (obj != null && !StringUtils.isEmpty(obj.getSfysqm())) {
            sfysqmpic = obj.getSfysqm();
            sfysqm.setImageBitmap(BitmapFactory.decodeFile(Environment.getExternalStorageDirectory() + "/" + sfysqmpic + ".jpg"));
        }
        //本人或家属签名
        brqm = (ImageView) findViewById(R.id.brqm);
        brqm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivityForResult(new Intent(con, WriteActivity.class)
                        .putExtra("cardnum", obj.getCARDNUM())
                        .putExtra("tabId", null==obj.getSFJLH()||"".equals(obj.getSFJLH()) ? "noid" : obj.getSFJLH())
                        .putExtra("tabType", "fjhdycrhsf")
                        .putExtra("imageType", "img")
                        .putExtra("class", "fjhdycrhsf.class"), 9);
            }
        });
        if (obj != null && !StringUtils.isEmpty(obj.getBrqm())) {
            brqmpic = obj.getBrqm();
            brqm.setImageBitmap(BitmapFactory.decodeFile(Environment.getExternalStorageDirectory() + "/" + brqmpic + ".jpg"));
        }
        xcqm = (ImageView) findViewById(R.id.xcqm);
        if (obj != null && !StringUtils.isEmpty(obj.getXcqm())) {
            xcqmpic = obj.getXcqm();
            xcqm.setImageBitmap(BitmapFactory.decodeFile(Environment.getExternalStorageDirectory() + "/" + xcqmpic + ".jpg"));
        }
        xcqm.setOnClickListener(new CustomerListener());
        //现场拍照
        xcpaizhao = (ImageView) findViewById(R.id.xcpaizhao);
        xcpaizhao.setOnClickListener(new CustomerListener());
        //现场拍照照片id
        pz_record_id = (TextView) findViewById(R.id.pz_record_id);
        if(obj != null && !StringUtils.isEmpty(obj.getImg2())) {
            //fjhdycrhsf/D24E75C5BB5E417EBE65494CA09BF399.jpg
            String[] img2Arr =obj.getImg2().split("/");
            if(null !=img2Arr && img2Arr.length>1){
                pz_record_id.setText(img2Arr[1]);
            }
        }
        jmqm_record_id= (TextView) findViewById(R.id.jmqm_record_id);
        if(obj != null && !StringUtils.isEmpty(obj.getImg())) {
            String[] img2Arr =obj.getImg().split("/");
            if(null !=img2Arr && img2Arr.length>1){
                jmqm_record_id.setText(img2Arr[1]);
            }
        }
        ysqm_record_id= (TextView) findViewById(R.id.ysqm_record_id);
        if(obj != null && !StringUtils.isEmpty(obj.getImg1())) {
            //fjhdycrhsf/D24E75C5BB5E417EBE65494CA09BF399.jpg
            String[] img2Arr =obj.getImg1().split("/");
            if(null !=img2Arr && img2Arr.length>1){
                ysqm_record_id.setText(img2Arr[1]);
            }
        }

        back = (LinearLayout) findViewById(R.id.back);
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(pzChange){
                   SweetAlertDialogUtil.WarningDialogHaveCancelAndConfirm(con,"你确认不保存数据更新吗？","现场拍照已经采集，请注意点击“保存”","确定", "返回");
                }else {
                    finish();
                }
            }
        });
        //标题
        title = (TextView) findViewById(R.id.title);
        uname = (TextView) findViewById(R.id.uname);
        title.setText("肺结核患者第一次入户随访记录");
        uname.setText("保存");
        uname.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                FjhDycrhsf fjhDycrhsf = new FjhDycrhsf();
                boolean validate = BinderUtil.copyDataToView(fjhdycrhsf.this, obj);
                if(!validate){

                }else if ("1".equals(SharedPreferencesUtils.getParam(con, "ysqm", "0").toString()) && ysqm_record_id.getText().toString().equals("noid")) {
                    SweetAlertDialogUtil.WarningDialog(con, "提示", "随访医生签名不能为空");
                }else if ("1".equals(SharedPreferencesUtils.getParam(con, "jmqm", "0").toString()) && jmqm_record_id.getText().toString().equals("noid")) {
                    SweetAlertDialogUtil.WarningDialog(con, "提示", "家属或本人签名不能为空");
                }else if ("1".equals(SharedPreferencesUtils.getParam(con, "xcpz", "0").toString()) && pz_record_id.getText().toString().equals("noid")) {
                    SweetAlertDialogUtil.WarningDialog(con, "提示", "现场拍照不能为空");
                } else if (NetWorkUtils.isNetworkConnected(con)) {  ///网络连接
                    RequestParams ps = BinderUtil.generateRequestParamsByView(fjhdycrhsf.this);
                    if (isadd) {
                        ps.add("entity.JKDAH", JKDAH);
                        url = HttpUrl.SaveFjhDycrhsf;
                    } else {
                        ps.add("entity.SFJLH", obj.getSFJLH());
                        ps.add("entity.JKDAH", obj.getJKDAH());
                        url = HttpUrl.EditFjhDycrhsf;
                    }
                    ps.add("entity.SFFS", obj.getSFFS());
                    ps.add("entity.HZLX", obj.getHZLX());
                    ps.add("entity.TJQK", obj.getTJQK());
                    ps.add("entity.NYQK", obj.getNYQK());
                    //zzjtz, yplx
                    ArrayList<Integer> zdlist = zzjtz.getAllItemSelectedIndex();
                    String bjzds = "";
                    for (int i = 0; i < zdlist.size(); i++) {
                        if (i == 0)
                            bjzds =  (Integer.parseInt(zdlist.get(i)+"")+1)+ "";
                        else
                            bjzds = bjzds + "," + (Integer.parseInt(zdlist.get(i)+"")+1);
                    }
                    ps.add("entity.ZHENGZHUANG", bjzds);
                    //zzjtz, yplx
                    ArrayList<Integer> jllist = yplx.getAllItemSelectedIndex();
                    String jxzds = "";
                    for (int i = 0; i < jllist.size(); i++) {
                        if (i == 0)
                            jxzds = (Integer.parseInt(jllist.get(i)+"")+1) + "";
                        else
                            jxzds = jxzds + "," + (Integer.parseInt(jllist.get(i)+"")+1);
                    }
                    ps.add("entity.YPJX", jxzds);
                    ps.add("entity.YYYF", obj.getYYYF());
                    ps.add("entity.DDRYXZ", obj.getDDRYXZ());
                    //家庭居住环境评估
                    ps.add("entity.SFDDJS", obj.getSFDDJS());
                    ps.add("entity.JSTFQK", obj.getJSTFQK());
                    ps.add("entity.FYJLKTX", obj.getFYJLKTX());
                    ps.add("entity.FYFFJYPCF", obj.getFYFFJYPCF());
                    ps.add("entity.FJHZLLC", obj.getFJHZLLC());
                    ps.add("entity.BGLFYWH", obj.getBGLFYWH());
                    ps.add("entity.FYHBLFYJCL", obj.getFYHBLFYJCL());
                    ps.add("entity.ZLQJFZCT", obj.getZLQJFZCT());
                    ps.add("entity.WCQJRHJCFY", obj.getWCQJRHJCFY());
                    ps.add("entity.SHXGJZYSX", obj.getSHXGJZYSX());
                    ps.add("entity.MQJCZJC", obj.getMQJCZJC());

                    ps.add("entity.CARDNUM", obj.getCARDNUM());
                    ps.add("token", SharedPreferencesUtils.getParam(con, "token", "").toString());
                    ps.add("type", "2");

                    ps.add("pz_record_id", pz_record_id.getText().toString());
                    ps.add("jmqm_record_id", jmqm_record_id.getText().toString());
                    ps.add("ysqm_record_id", jmqm_record_id.getText().toString());
                    ps.add("entity.UPDATETIME", obj.getUPDATETIME());
                    //fjhdycrhsf.super.ImageUploadOperate(sfysqmpic, brqmpic, ps);
                    UserClient.get(url, ps, new AsyncHttpResponseHandler() {
                        @Override
                        public void onSuccess(int statusCode, Header[] headers, byte[] response) {
                            String content = new String(response);
                            RetMsg ret = JSON.parseObject(content, RetMsg.class);
                            if (ret.getCode().equals("200")) {
                                MyToastUtil.ShowToast(con, "成功");
                            }else{
                                MyToastUtil.ShowToast(con, ret.getInfo());
                            }
                            finish();
                        }

                        @Override
                        public void onFailure(int statusCode, Header[] headers, byte[] errorResponse, Throwable e) {

                            MyToastUtil.ShowToast(con, "失败");
                        }
                    });
                } else {

                }
            }
        });
        //xm = (EditText) findViewById(R.id.xm);
        if (obj != null && !StringUtils.isEmpty(obj.getXINGMING())) {
            XINGMING.setText(obj.getXINGMING());
        } else {
            XINGMING.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    startActivityForResult(new Intent(con, choose_user.class).putExtra("cname", "fjhdycrhsf.class"), 1);
                }
            });
        }
        SFRQ.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.CHINA);
                String now = sdf.format(new Date());
                customDatePicker = new CustomDatePicker(con, new CustomDatePicker.ResultHandler() {
                    @Override
                    public void handle(String time) { // 回调接口，获得选中的时间
                        SFRQ.setText(time.split(" ")[0]);

                    }
                }, "2010-01-01 00:00", now); // 初始化日期格式请用：yyyy-MM-dd HH:mm，否则不能正常运行
                customDatePicker.showSpecificTime(false); // 不显示时和分
                customDatePicker.setIsLoop(false); // 不允许循环滚动
                customDatePicker.show(now);
            }
        });
        if(obj != null && !StringUtils.isEmpty(obj.getSFRQ())){
            SFRQ.setText(DateConvert.dateToString(DateConvert.toDate(obj.getSFRQ(), DateConvert.YMD), DateConvert.YMD)+"");
        }
        XCSFRQ.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.CHINA);
                customDatePicker = new CustomDatePicker(con, new CustomDatePicker.ResultHandler() {
                    @Override
                    public void handle(String time) { // 回调接口，获得选中的时间
                        XCSFRQ.setText(time.split(" ")[0]);

                    }
                }, DateConvert.getCustomDatePickerStartRq(), DateConvert.getCustomDatePickerEndRq()); // 初始化日期格式请用：yyyy-MM-dd HH:mm，否则不能正常运行
                customDatePicker.showSpecificTime(false); // 不显示时和分
                customDatePicker.setIsLoop(false); // 不允许循环滚动
                customDatePicker.show(DateConvert.getCustomDatePickerNowRq());
            }
        });
        if(obj != null && !StringUtils.isEmpty(obj.getXCSFRQ())){
            XCSFRQ.setText(DateConvert.dateToString(DateConvert.toDate(obj.getXCSFRQ(), DateConvert.YMD), DateConvert.YMD)+"");
        }
        sffs = (RadioGroup) findViewById(R.id.sffs);
        if (obj != null && !StringUtils.isEmpty(obj.getSFFS())) {
            switch (Integer.parseInt(obj.getSFFS())) {
                case 1:
                    sffs.check(R.id.sffs1);
                    break;
                case 2:
                    sffs.check(R.id.sffs2);
                    break;

            }
        }
        sffs.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (checkedId == R.id.sffs1) {
                    obj.setSFFS("1");
                } else {
                    obj.setSFFS("2");
                }
            }
        });
        //患者类型
        hzlx = (RadioGroup) findViewById(R.id.hzll);
        if (obj != null && !StringUtils.isEmpty(obj.getHZLX())) {
            switch (Integer.parseInt(obj.getHZLX())) {
                case 1:
                    hzlx.check(R.id.hzll1);
                    break;
                case 2:
                    hzlx.check(R.id.hzll2);
                    break;

            }
        }
        hzlx.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (checkedId == R.id.hzll1) {
                    obj.setHZLX("1");
                } else {
                    obj.setHZLX("2");
                }
            }
        });
        //痰菌情况
        tjqk = (RadioGroup) findViewById(R.id.tjqk);
        if (obj != null && !StringUtils.isEmpty(obj.getTJQK())) {
            switch (Integer.parseInt(obj.getTJQK())) {
                case 1:
                    tjqk.check(R.id.tjqk1);
                    break;
                case 2:
                    tjqk.check(R.id.tjqk2);
                    break;
                case 3:
                    tjqk.check(R.id.tjqk3);
                    break;
            }
        }
        tjqk.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (checkedId == R.id.tjqk1) {
                    obj.setTJQK("1");
                } else if (checkedId == R.id.tjqk2) {
                    obj.setTJQK("2");
                } else {
                    obj.setTJQK("3");
                }
            }
        });
        //耐药
        nyqk = (RadioGroup) findViewById(R.id.nyqk);
        if (obj != null && !StringUtils.isEmpty(obj.getNYQK())) {
            switch (Integer.parseInt(obj.getNYQK())) {
                case 1:
                    nyqk.check(R.id.nyqk1);
                    break;
                case 2:
                    nyqk.check(R.id.nyqk2);
                    break;
                case 3:
                    nyqk.check(R.id.nyqk3);
                    break;
            }
        }
        nyqk.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (checkedId == R.id.nyqk1) {
                    obj.setNYQK("1");
                } else if (checkedId == R.id.nyqk2) {
                    obj.setNYQK("2");
                } else {
                    obj.setNYQK("3");
                }
            }
        });
        zzjtz = (MultiLineChooseLayout) findViewById(R.id.zzjtz);
        zzjtzdata.add("没有症状");
        zzjtzdata.add("咳嗽咳痰");
        zzjtzdata.add("低热盗汗");
        zzjtzdata.add("咯血或血痰");
        zzjtzdata.add("胸痛消瘦");
        zzjtzdata.add("恶心纳差");
        zzjtzdata.add("头痛失眠");
        zzjtzdata.add("视物模糊");
        zzjtzdata.add("皮肤瘙痒、皮疹");
        zzjtzdata.add("皮肤瘙痒、皮疹");
        zzjtzdata.add("其他");
        zzjtz.setList(zzjtzdata);
        if (obj != null && !StringUtils.isEmpty(obj.getZHENGZHUANG())) {
            String[] zzList = obj.getZHENGZHUANG().split(",");

            if (Arrays.asList(zzList).contains("1"))
                zzjtz.setIndexItemSelected(0);
            if (Arrays.asList(zzList).contains("2"))
                zzjtz.setIndexItemSelected(1);
            if (Arrays.asList(zzList).contains("3"))
                zzjtz.setIndexItemSelected(2);
            if (Arrays.asList(zzList).contains("4"))
                zzjtz.setIndexItemSelected(3);
            if (Arrays.asList(zzList).contains("5"))
                zzjtz.setIndexItemSelected(4);
            if (Arrays.asList(zzList).contains("6"))
                zzjtz.setIndexItemSelected(5);
            if (Arrays.asList(zzList).contains("7"))
                zzjtz.setIndexItemSelected(6);
            if (Arrays.asList(zzList).contains("8"))
                zzjtz.setIndexItemSelected(7);
            if (Arrays.asList(zzList).contains("9"))
                zzjtz.setIndexItemSelected(8);
            if (Arrays.asList(zzList).contains("10"))
                zzjtz.setIndexItemSelected(9);
            if (Arrays.asList(zzList).contains("11"))
                zzjtz.setIndexItemSelected(10);
        }
        //症状及体征其他
        //zzjtzqt = (EditText) findViewById(R.id.zzjtzqt);
        if (obj != null && !StringUtils.isEmpty(obj.getZZQT())) {
            ZZQT.setText(obj.getZZQT());
        }
        //化疗方案
        //hlfa = (EditText) findViewById(R.id.hlfa);
        if (obj != null && !StringUtils.isEmpty(obj.getYYHLFA())) {
            YYHLFA.setText(obj.getYYHLFA());
        }
        //用法
        yf = (RadioGroup) findViewById(R.id.yf);
        if (obj != null && !StringUtils.isEmpty(obj.getYYYF())) {
            switch (Integer.parseInt(obj.getYYYF())) {
                case 1:
                    yf.check(R.id.yf1);
                    break;
                case 2:
                    yf.check(R.id.yf2);
                    break;

            }
        }
        yf.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (checkedId == R.id.yf1) {
                    obj.setYYYF("1");
                } else {
                    obj.setYYYF("2");
                }
            }
        });
        //药品剂型
        yplx = (MultiLineChooseLayout) findViewById(R.id.ypjx);
        yplxdata.add("固定剂量复合制剂");
        yplxdata.add("散装药");
        yplxdata.add("板式组合药");
        yplxdata.add("注射剂");
        yplx.setList(yplxdata);
        if (obj != null && !StringUtils.isEmpty(obj.getYPJX())) {
            if (obj.getYPJX().contains("1"))
                yplx.setIndexItemSelected(0);
            if (obj.getYPJX().contains("2"))
                yplx.setIndexItemSelected(1);
            if (obj.getYPJX().contains("3"))
                yplx.setIndexItemSelected(2);
            if (obj.getYPJX().contains("4"))
                yplx.setIndexItemSelected(3);
        }
        //督导人员选择
        ddryxz = (RadioGroup) findViewById(R.id.jdryxz);
        if (obj != null && !StringUtils.isEmpty(obj.getDDRYXZ())) {
            switch (Integer.parseInt(obj.getDDRYXZ())) {
                case 1:
                    ddryxz.check(R.id.jdryxz1);
                    break;
                case 2:
                    ddryxz.check(R.id.jdryxz2);
                    break;
                case 3:
                    ddryxz.check(R.id.jdryxz3);
                    break;
                case 4:
                    ddryxz.check(R.id.jdryxz4);
                    break;

            }
        }
        ddryxz.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (checkedId == R.id.jdryxz1) {
                    obj.setDDRYXZ("1");
                } else if (checkedId == R.id.jdryxz2) {
                    obj.setDDRYXZ("2");
                } else if (checkedId == R.id.jdryxz3) {
                    obj.setDDRYXZ("3");
                } else {
                    obj.setDDRYXZ("4");
                }
            }
        });
        //单独的居室
        dddjs = (RadioGroup) findViewById(R.id.dddjs);
        if (obj != null && !StringUtils.isEmpty(obj.getSFDDJS())) {
            System.out.println("obj.getSFDDJS()===>" + obj.getSFDDJS());
            switch (Integer.parseInt(obj.getSFDDJS())) {
                case 1:
                    dddjs.check(R.id.dddjs1);
                    break;
                case 2:
                    dddjs.check(R.id.dddjs2);
                    break;
            }
        }
        dddjs.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (checkedId == R.id.dddjs1) {
                    obj.setSFDDJS("1");
                } else {
                    obj.setSFDDJS("2");
                }
            }
        });
        //居室通风情况
        tfqk = (RadioGroup) findViewById(R.id.tfqk);
        if (obj != null && !StringUtils.isEmpty(obj.getJSTFQK())) {
            switch (Integer.parseInt(obj.getJSTFQK())) {
                case 1:
                    tfqk.check(R.id.tfqk1);
                    break;
                case 2:
                    tfqk.check(R.id.tfqk2);
                    break;
                case 3:
                    tfqk.check(R.id.tfqk3);
                    break;

            }
        }
        tfqk.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (checkedId == R.id.tfqk1) {
                    obj.setJSTFQK("1");
                } else if (checkedId == R.id.tfqk2) {
                    obj.setJSTFQK("2");
                } else if (checkedId == R.id.tfqk3) {
                    obj.setJSTFQK("3");
                } else {
                    obj.setJSTFQK("4");
                }
            }
        });
        //xiyan = (EditText) findViewById(R.id.rxyl);
        if (obj != null && !StringUtils.isEmpty(obj.getSHXY())) {
            SHXY.setText(obj.getSHXY());
        }
        if (obj != null && !StringUtils.isEmpty(obj.getSHXYZD())) {
            SHXYZD.setText(obj.getSHXYZD());
        }
        //yinjiu = (EditText) findViewById(R.id.ryjl);
        if (obj != null && !StringUtils.isEmpty(obj.getSHYJ())) {
            SHYJ.setText(obj.getSHYJ());
        }
        if (obj != null && !StringUtils.isEmpty(obj.getSHYJZD())) {
            SHYJZD.setText(obj.getSHYJ());
        }

        //qydd = (EditText) findViewById(R.id.qydd);
        if (obj != null && !StringUtils.isEmpty(obj.getQYDD())) {
            QYDD.setText(obj.getQYDD());
        }
        //qysj = (EditText) findViewById(R.id.qysj);
        QYSJ.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.CHINA);
                String now = sdf.format(new Date());
                customDatePicker = new CustomDatePicker(con, new CustomDatePicker.ResultHandler() {
                    @Override
                    public void handle(String time) { // 回调接口，获得选中的时间
                        QYSJ.setText(time.split(" ")[0]);

                    }
                }, "2010-01-01 00:00", now); // 初始化日期格式请用：yyyy-MM-dd HH:mm，否则不能正常运行
                customDatePicker.showSpecificTime(false); // 不显示时和分
                customDatePicker.setIsLoop(false); // 不允许循环滚动
                customDatePicker.show(now);
            }
        });
        if(obj != null && !StringUtils.isEmpty(obj.getQYSJ())){
            QYSJ.setText(DateConvert.dateToString(DateConvert.toDate(obj.getQYSJ(), DateConvert.YMD), DateConvert.YMD)+"    ");
        }
        //服药记录卡的填写
        r1 = (RadioGroup) findViewById(R.id.r1);
        if (obj != null && !StringUtils.isEmpty(obj.getFYJLKTX())) {
            switch (Integer.parseInt(obj.getFYJLKTX())) {
                case 1:
                    r1.check(R.id.r11);
                    break;
                case 2:
                    r1.check(R.id.r12);
                    break;
            }
        }
        r1.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (checkedId == R.id.r11) {
                    obj.setFYJLKTX("1");
                } else {
                    obj.setFYJLKTX("2");
                }
            }
        });
        //服药方法及药品存放
        r2 = (RadioGroup) findViewById(R.id.r2);
        if (obj != null && !StringUtils.isEmpty(obj.getFYFFJYPCF())) {
            switch (Integer.parseInt(obj.getFYFFJYPCF())) {
                case 1:
                    r2.check(R.id.r21);
                    break;
                case 2:
                    r2.check(R.id.r22);
                    break;
            }
        }
        r2.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (checkedId == R.id.r21) {
                    obj.setFYFFJYPCF("1");
                } else {
                    obj.setFYFFJYPCF("2");
                }
            }
        });
        //肺结核治疗疗程
        r3 = (RadioGroup) findViewById(R.id.r3);
        if (obj != null && !StringUtils.isEmpty(obj.getFJHZLLC())) {
            switch (Integer.parseInt(obj.getFJHZLLC())) {
                case 1:
                    r3.check(R.id.r31);
                    break;
                case 2:
                    r3.check(R.id.r32);
                    break;
            }
        }
        r3.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (checkedId == R.id.r31) {
                    obj.setFJHZLLC("1");
                } else {
                    obj.setFJHZLLC("2");
                }
            }
        });
        //不规律服药危害
        r4 = (RadioGroup) findViewById(R.id.r4);
        if (obj != null && !StringUtils.isEmpty(obj.getBGLFYWH())) {
            switch (Integer.parseInt(obj.getBGLFYWH())) {
                case 1:
                    r4.check(R.id.r41);
                    break;
                case 2:
                    r4.check(R.id.r42);
                    break;
            }
        }
        r4.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (checkedId == R.id.r41) {
                    obj.setBGLFYWH("1");
                } else {
                    obj.setBGLFYWH("2");
                }
            }
        });
        //服药后不良反应及处理
        r5 = (RadioGroup) findViewById(R.id.r5);
        if (obj != null && !StringUtils.isEmpty(obj.getFYHBLFYJCL())) {
            switch (Integer.parseInt(obj.getFYHBLFYJCL())) {
                case 1:
                    r5.check(R.id.r51);
                    break;
                case 2:
                    r5.check(R.id.r52);
                    break;
            }
        }
        r5.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (checkedId == R.id.r51) {
                    obj.setFYHBLFYJCL("1");
                } else {
                    obj.setFYHBLFYJCL("2");
                }
            }
        });
        //治疗期间复诊查痰
        r6 = (RadioGroup) findViewById(R.id.r6);
        if (obj != null && !StringUtils.isEmpty(obj.getZLQJFZCT())) {
            switch (Integer.parseInt(obj.getZLQJFZCT())) {
                case 1:
                    r6.check(R.id.r61);
                    break;
                case 2:
                    r6.check(R.id.r62);
                    break;
            }
        }
        r6.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (checkedId == R.id.r61) {
                    obj.setZLQJFZCT("1");
                } else {
                    obj.setZLQJFZCT("2");
                }
            }
        });
        //外出期间如何坚持服药
        r7 = (RadioGroup) findViewById(R.id.r7);
        if (obj != null && !StringUtils.isEmpty(obj.getWCQJRHJCFY())) {
            switch (Integer.parseInt(obj.getWCQJRHJCFY())) {
                case 1:
                    r7.check(R.id.r71);
                    break;
                case 2:
                    r7.check(R.id.r72);
                    break;
            }
        }
        r7.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (checkedId == R.id.r71) {
                    obj.setWCQJRHJCFY("1");
                } else {
                    obj.setWCQJRHJCFY("2");
                }
            }
        });
        //生活习惯及注意事项
        r8 = (RadioGroup) findViewById(R.id.r8);
        if (obj != null && !StringUtils.isEmpty(obj.getSHXGJZYSX())) {
            switch (Integer.parseInt(obj.getSHXGJZYSX())) {
                case 1:
                    r8.check(R.id.r81);
                    break;
                case 2:
                    r8.check(R.id.r82);
                    break;
            }
        }
        r8.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (checkedId == R.id.r81) {
                    obj.setSHXGJZYSX("1");
                } else {
                    obj.setSHXGJZYSX("2");
                }
            }
        });
        //密切接触者检查
        r9 = (RadioGroup) findViewById(R.id.r9);
        if (obj != null && !StringUtils.isEmpty(obj.getMQJCZJC())) {
            switch (Integer.parseInt(obj.getMQJCZJC())) {
                case 1:
                    r9.check(R.id.r91);
                    break;
                case 2:
                    r9.check(R.id.r92);
                    break;
            }
        }
        r9.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (checkedId == R.id.r91) {
                    obj.setMQJCZJC("1");
                } else {
                    obj.setMQJCZJC("2");
                }
            }
        });
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initListener() {

    }

    class CustomerListener implements View.OnClickListener {
        @Override
        public void onClick(View v) {
            if(obj != null && StringUtils.isEmpty(obj.getJKDAH())) {
                SweetAlertDialogUtil.WarningDialog(con, "提示", "选择居民用户后才能现场拍照");
            }else {
                Intent intent = new Intent(con, CameraChoose.class)
                        .putExtra("type", "edit")
                        .putExtra("cardnum", obj.getCARDNUM())
                        .putExtra("tabId", null==obj.getSFJLH()||"".equals(obj.getSFJLH()) ? "noid" : obj.getSFJLH())
                        .putExtra("tabType", "fjhdycrhsf")
                        .putExtra("class", "fjhdycrhsf.class");
                startActivityForResult(intent, 119);
            }
        }
    }
}
